<?php

defined('BASEPATH') or die('forbidden');

class skillhotkey_Controller Extends Controller {

    private $rolename;
	private $dbConnt;	//数据库连接
	private $skilllist;	//技能列表
	private $isskill;	//类型
	
    function _init() {
        check_level(50, segment(0), segment(1));
    	set_time_limit(0);
		$this->inc = $this->config['inc'];
        $this->skilllist = get_type_skill();
        $this->isskill = array('0'=>'技能','1'=>'消耗品');
        //得到选择的区号
        $areanum = $_SESSION['area_selected_id'];
        if ($areanum == '') 
        {
            echo "<script>alert('" . translate('C_SELECT_AREA_TEXT') . "');</script>";
            return;
        }
        // db数据库
        $this->dbConnt = getTmpDbConnect(PLATFORM_ALL, 'all', $areanum, DBTYPE_GAMESERVER);
		
        if (false == $this->dbConnt) {
            //内部有提示错误，在此就不提示了
            //echo "<script>alert(' connect areanum:$areanum error ');</script>";
            return;
        }
    }

    function index() {
        $this->view->display("dbplayer/skillhotkey/index");
    }

    function flexigrid() {
        list($colkey, $colsinfo, $where, $sortname, $sortorder, $offset, $rp, $page) = $this->common->get_flexigrid_params();
			
		
		$sql = "SELECT COUNT(*) AS num FROM player_skillhotkey  WHERE {$where} {$exwhere}";
		//echo " sql2:$sql ";
		$one = $this->dbConnt->one($sql);
		$total = $one['num'];
		$orderby = $sortname ? "ORDER BY {$sortname} {$sortorder} " : "";
		 
		$sql = "SELECT {$colsinfo} FROM player_skillhotkey WHERE {$where} {$exwhere} {$orderby} LIMIT {$offset},{$rp}";
		$this->dbConnt->query($sql);
		//$id = 0;
		while ($n = $this->dbConnt->get_array('default'))
		{
			$n['skillid']=$this->skilllist[$n['skillid']]."-".$n['skillid'];
			$n['isskill']=$this->isskill[$n['isskill']]."-".$n['isskill'];
			//$n['lastfire']=get_datetime($n['lastfire']);
			$rows[] = array('id' => $n['id'], 'cell' => $n);
			//$id = $id+1;
		}
		//var_dump($rows);
		$result = array(
	            'page' => $page,
	            'total' => $total,
	            'rows' => $rows
		);
		//$this->dbConnt->free_all();
		echo json_encode($result);
    }

}

?>
